package vip.denglei.company.util;

import com.alibaba.fastjson.JSONObject;
import vip.denglei.company.model.workwechat.AccessToken;

public class WorkWechatUtils {

    /**
     * 应用相关
     */
    private final static String AgentId="1000009";
    private final static String Secret="IMdZZNIbvpE9p0pwlGvopjEiSLOse-ZnHOP46UW1-rM";

    /**
     * 企业ID
     */
    private  final static String WORK_WECHAT_COMPANY_ID="wwc846e11b754ed19a";

    public static void sendAppMsg(String touser,String content){
     JSONObject param = new JSONObject();
     param.put("agentid",AgentId);
     param.put("app_secret",Secret);
     param.put("touser",touser);
     param.put("msgtype","text");
     JSONObject text = new JSONObject();
     text.put("content",content);
     param.put("text",text);
        HttpResult.success( HttpClientUtil.doPostJson("https://qyapi.weixin.qq.com/cgi-bin/message/send?access_token="+getToken(Secret), param.toString()));
    }


    public static String getToken(String corpsecret){
        String url="https://qyapi.weixin.qq.com/cgi-bin/gettoken?corpid="+WORK_WECHAT_COMPANY_ID+"&corpsecret="+corpsecret;
        String json= HttpClientUtil.doGet(url);
        AccessToken accessToken=JsonUtils.jsonToPojo(json, AccessToken.class);
        return accessToken.getAccess_token();
    }


}
